/*
 * $Id: ctype.c,v 1.16 2005-08-06 04:10:11 bacon Exp $
 */

#include <xp/bas/ctype.h>
#include <xp/bas/ctype_unicode.h>
#include <ctype.h>

static xp_bool_t __xp_misupper (xp_mcint_t c);
static xp_bool_t __xp_mislower (xp_mcint_t c);
static xp_bool_t __xp_misalpha (xp_mcint_t c);
static xp_bool_t __xp_misdigit (xp_mcint_t c);
static xp_bool_t __xp_misxdigit (xp_mcint_t c);
static xp_bool_t __xp_misalnum (xp_mcint_t c);
static xp_bool_t __xp_misspace (xp_mcint_t c);
static xp_bool_t __xp_misprint (xp_mcint_t c);
static xp_bool_t __xp_misgraph (xp_mcint_t c);
static xp_bool_t __xp_miscntrl (xp_mcint_t c);
static xp_bool_t __xp_mispunct (xp_mcint_t c);
static xp_mcint_t __xp_mtoupper (xp_mcint_t c);
static xp_mcint_t __xp_mtolower (xp_mcint_t c);

/* TODO: rewrite this portion */

#if defined(XP_CHAR_IS_MCHAR)

xp_bool_t (*xp_isupper)  (xp_cint_t c) = __xp_misupper;
xp_bool_t (*xp_islower)  (xp_cint_t c) = __xp_mislower;
xp_bool_t (*xp_isalpha)  (xp_cint_t c) = __xp_misalpha;
xp_bool_t (*xp_isdigit)  (xp_cint_t c) = __xp_misdigit;
xp_bool_t (*xp_isxdigit) (xp_cint_t c) = __xp_misxdigit;
xp_bool_t (*xp_isalnum)  (xp_cint_t c) = __xp_misalnum;
xp_bool_t (*xp_isspace)  (xp_cint_t c) = __xp_misspace;
xp_bool_t (*xp_isprint)  (xp_cint_t c) = __xp_misprint;
xp_bool_t (*xp_isgraph)  (xp_cint_t c) = __xp_misgraph;
xp_bool_t (*xp_iscntrl)  (xp_cint_t c) = __xp_miscntrl;
xp_bool_t (*xp_ispunct)  (xp_cint_t c) = __xp_mispunct;
xp_cint_t (*xp_toupper)  (xp_cint_t c) = __xp_mtoupper;
xp_cint_t (*xp_tolower)  (xp_cint_t c) = __xp_mtolower;

#else

xp_bool_t (*xp_isupper)  (xp_cint_t c) = xp_unicode_isupper;
xp_bool_t (*xp_islower)  (xp_cint_t c) = xp_unicode_islower;
xp_bool_t (*xp_isalpha)  (xp_cint_t c) = xp_unicode_isalpha;
xp_bool_t (*xp_isdigit)  (xp_cint_t c) = xp_unicode_isdigit;
xp_bool_t (*xp_isxdigit) (xp_cint_t c) = xp_unicode_isxdigit;
xp_bool_t (*xp_isalnum)  (xp_cint_t c) = xp_unicode_isalnum;
xp_bool_t (*xp_isspace)  (xp_cint_t c) = xp_unicode_isspace;
xp_bool_t (*xp_isprint)  (xp_cint_t c) = xp_unicode_isprint;
xp_bool_t (*xp_isgraph)  (xp_cint_t c) = xp_unicode_isgraph;
xp_bool_t (*xp_iscntrl)  (xp_cint_t c) = xp_unicode_iscntrl;
xp_bool_t (*xp_ispunct)  (xp_cint_t c) = xp_unicode_ispunct;
xp_cint_t (*xp_toupper)  (xp_cint_t c) = xp_unicode_toupper;
xp_cint_t (*xp_tolower)  (xp_cint_t c) = xp_unicode_tolower;

#endif

/* TODO: rewrite this portion */
xp_bool_t (*xp_misupper)  (xp_mcint_t c) = __xp_misupper;
xp_bool_t (*xp_mislower)  (xp_mcint_t c) = __xp_mislower;
xp_bool_t (*xp_misalpha)  (xp_mcint_t c) = __xp_misalpha;
xp_bool_t (*xp_misdigit)  (xp_mcint_t c) = __xp_misdigit;
xp_bool_t (*xp_misxdigit) (xp_mcint_t c) = __xp_misxdigit;
xp_bool_t (*xp_misalnum)  (xp_mcint_t c) = __xp_misalnum;
xp_bool_t (*xp_misspace)  (xp_mcint_t c) = __xp_misspace;
xp_bool_t (*xp_misprint)  (xp_mcint_t c) = __xp_misprint;
xp_bool_t (*xp_misgraph)  (xp_mcint_t c) = __xp_misgraph;
xp_bool_t (*xp_miscntrl)  (xp_mcint_t c) = __xp_miscntrl;
xp_bool_t (*xp_mispunct)  (xp_mcint_t c) = __xp_mispunct;
xp_mcint_t (*xp_mtoupper)  (xp_mcint_t c) = __xp_mtoupper;
xp_mcint_t (*xp_mtolower)  (xp_mcint_t c) = __xp_mtolower;

xp_bool_t (*xp_wisupper)  (xp_wcint_t c) = xp_unicode_isupper;
xp_bool_t (*xp_wislower)  (xp_wcint_t c) = xp_unicode_islower;
xp_bool_t (*xp_wisalpha)  (xp_wcint_t c) = xp_unicode_isalpha;
xp_bool_t (*xp_wisdigit)  (xp_wcint_t c) = xp_unicode_isdigit;
xp_bool_t (*xp_wisxdigit) (xp_wcint_t c) = xp_unicode_isxdigit;
xp_bool_t (*xp_wisalnum)  (xp_wcint_t c) = xp_unicode_isalnum;
xp_bool_t (*xp_wisspace)  (xp_wcint_t c) = xp_unicode_isspace;
xp_bool_t (*xp_wisprint)  (xp_wcint_t c) = xp_unicode_isprint;
xp_bool_t (*xp_wisgraph)  (xp_wcint_t c) = xp_unicode_isgraph;
xp_bool_t (*xp_wiscntrl)  (xp_wcint_t c) = xp_unicode_iscntrl;
xp_bool_t (*xp_wispunct)  (xp_wcint_t c) = xp_unicode_ispunct;
xp_wcint_t (*xp_wtoupper)  (xp_wcint_t c) = xp_unicode_toupper;
xp_wcint_t (*xp_wtolower)  (xp_wcint_t c) = xp_unicode_tolower;

static xp_bool_t __xp_misupper (xp_mcint_t c)
{
	return isupper(c)? xp_true: xp_false;
}

static xp_bool_t __xp_mislower (xp_mcint_t c)
{
	return islower(c)? xp_true: xp_false;
}

static xp_bool_t __xp_misalpha (xp_mcint_t c)
{
	return isalpha(c)? xp_true: xp_false;
}

static xp_bool_t __xp_misdigit (xp_mcint_t c)
{
	return isdigit(c)? xp_true: xp_false;
}

static xp_bool_t __xp_misxdigit (xp_mcint_t c)
{
	return isxdigit(c)? xp_true: xp_false;
}
static xp_bool_t __xp_misalnum (xp_mcint_t c)
{
	return isalnum(c)? xp_true: xp_false;
}

static xp_bool_t __xp_misspace (xp_mcint_t c)
{
	return isspace(c)? xp_true: xp_false;
}

static xp_bool_t __xp_misprint (xp_mcint_t c)
{
	return isprint(c)? xp_true: xp_false;
}

static xp_bool_t __xp_misgraph (xp_mcint_t c)
{
	return isgraph(c)? xp_true: xp_false;
}

static xp_bool_t __xp_miscntrl (xp_mcint_t c)
{
	return iscntrl(c)? xp_true: xp_false;
}

static xp_bool_t __xp_mispunct (xp_mcint_t c)
{
	return ispunct(c)? xp_true: xp_false;
}

static xp_mcint_t __xp_mtoupper (xp_mcint_t c) 
{
	return toupper (c);
}

static xp_mcint_t __xp_mtolower (xp_mcint_t c) 
{
	return tolower (c);
}

